import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsNotEmpty, IsOptional, IsString, MaxLength, ValidateIf } from 'class-validator';

export class PostCreateDto {
    @ApiPropertyOptional({ required: true, description: '标题' })
    @MaxLength(50, { message: '长度最大为50' })
    @IsString({ message: '文章标题为字符串' })
    @ValidateIf((o) => o.name != '')
    @IsNotEmpty({ message: '文章标题不能为空' })
    @IsOptional()
    title: string;

    @ApiPropertyOptional({ required: true, description: '内容' })
    @IsString({ message: '内容为字符串' })
    @ValidateIf((o) => o.content != '')
    @IsNotEmpty({ message: '内容不能为空' })
    @IsOptional()
    content: string;

    @ApiPropertyOptional({ required: true, description: '类目' })
    @IsString({ message: '类目为字符串' })
    @ValidateIf((o) => o.content != '')
    @IsNotEmpty({ message: '类目不能为空' })
    @IsOptional()
    categoryId: number;

    @ApiPropertyOptional({ required: true, description: '标签' })
    tagIds: number[];
}